home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Blender 2.49b / blender-2.49b-windows.exe / $_4_ / .blender / scripts / weightpaint_copy.py < prev    next >
Text File  |  2009-08-31  |  3KB  |  101 lines

  1. #!BPY
  2. """
  3. Name: 'Copy Active Group...'
  4. Blender: 243
  5. Group: 'WeightPaint'
  6. Tooltip: 'Copy the active group to a new one'
  7. """
  8.  
  9. __author__ = ["Campbell Barton"]
  10. __url__ = ("blender.org",)
  11. __version__ = "0.1"
  12. __bpydoc__ = """\
  13.  
  14. Active Group Copy
  15.  
  16. This script makes a copy of the active group
  17. """
  18.  
  19. # ***** BEGIN GPL LICENSE BLOCK *****
  20. #
  21. # Script copyright (C) Campbell J Barton
  22. #
  23. # This program is free software; you can redistribute it and/or
  24. # modify it under the terms of the GNU General Public License
  25. # as published by the Free Software Foundation; either version 2
  26. # of the License, or (at your option) any later version.
  27. #
  28. # This program is distributed in the hope that it will be useful,
  29. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  31. # GNU General Public License for more details.
  32. #
  33. # You should have received a copy of the GNU General Public License
  34. # along with this program; if not, write to the Free Software Foundation,
  35. # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  36. #
  37. # ***** END GPL LICENCE BLOCK *****
  38. # --------------------------------------------------------------------------
  39.  
  40. from Blender import Scene, Draw, Window, Mesh
  41. import BPyMesh
  42. SMALL_NUM= 0.000001
  43. def copy_act_vgroup(me, PREF_NAME, PREF_SEL_ONLY):
  44.     Window.WaitCursor(1)
  45.     groupNames, vWeightDict= BPyMesh.meshWeight2Dict(me)
  46.     act_group= me.activeGroup
  47.     
  48.     if not PREF_SEL_ONLY:
  49.         for wd in vWeightDict:
  50.             try:        wd[PREF_NAME] = wd[act_group]
  51.             except:        pass
  52.     else:
  53.         # Selected faces only
  54.         verts = {} # should use set
  55.         for f in me.faces:
  56.             if f.sel:
  57.                 for v in f:
  58.                     verts[v.index] = None
  59.         
  60.         for i in verts.iterkeys():
  61.             wd = vWeightDict[i]
  62.             try:        wd[PREF_NAME] = wd[act_group]
  63.             except:        pass
  64.         
  65.         
  66.     
  67.     groupNames.append(PREF_NAME)
  68.     # Copy weights back to the mesh.
  69.     BPyMesh.dict2MeshWeight(me, groupNames, vWeightDict)
  70.     Window.WaitCursor(0)
  71.  
  72. def main():
  73.     scn= Scene.GetCurrent()
  74.     ob= scn.objects.active
  75.     
  76.     if not ob or ob.type != 'Mesh':
  77.         Draw.PupMenu('Error, no active mesh object, aborting.')
  78.         return
  79.     
  80.     me= ob.getData(mesh=1)
  81.     act_group= me.activeGroup
  82.     
  83.     PREF_NAME= Draw.Create(act_group + '_copy')
  84.     PREF_SEL_ONLY = Draw.Create(0)
  85.     
  86.     pup_block= [\
  87.     ('', PREF_NAME, 0, 31, 'Name of group copy.'),\
  88.     ('Only Selected', PREF_SEL_ONLY, 'Only include selected faces in the new grop.'),\
  89.     ]
  90.     
  91.     if not Draw.PupBlock('New Name...', pup_block):
  92.         return
  93.     PREF_NAME = PREF_NAME.val
  94.     PREF_SEL_ONLY = PREF_SEL_ONLY.val
  95.     copy_act_vgroup(me, PREF_NAME, PREF_SEL_ONLY)
  96.     
  97.     try:    me.activeGroup = PREF_NAME
  98.     except: pass
  99.  
  100. if __name__=='__main__':
  101.     main()